package com.supplychain.scm.core.common.validator.date;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.NumberUtil;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class TimestampValidator implements ConstraintValidator<Timestamp, Object> {

	@Override
	public void initialize(Timestamp annotation) {
	}

	@Override
	public boolean isValid(Object value, ConstraintValidatorContext context) {
		// 如果日期为空，默认不校验，即校验通过
		if (value == null) {
			return true;
		}
		//校验时间戳
		String timestamp = Convert.toStr(value);
		if (timestamp.length() != 13 ||
				!NumberUtil.isNumber(timestamp)) {
			return false;
		}
        return true;
    }

}
